<template>
    <div class="share_wrapper" :style="{height: searchVisible ? '100%' : ''}">
        <div class="search_wrapper" v-if="searchVisible">
            <div class="search_filter">
                <el-input type="search" v-model="keyword" @input="searchKeyword" placeholder="请输入搜索内容">
                    <i slot="prefix" class="el-input__icon el-icon-search"></i>
                </el-input>
                <el-button type="text" @click="cancelSearch">取消</el-button>
            </div>
            <div class="company_intro">
                <ul class="link_group">
                    <li>店铺主页</li>&nbsp;|&nbsp;
                    <li>个人中心</li>&nbsp;|&nbsp;
                    <li>投诉建议</li> 
                </ul>            
                <p class="support_name">知了提供技术支持</p>
            </div>
        </div>
        <div class="share_column" v-else>
            <div class="header">
                <h6 class="title">{{ shopname }}</h6>
                <div class="person_center">
                    <van-icon name="search" @click="searchProduct" />
                    <span class="name" @click="GoPersonCenter">个人中心</span>
                </div>
            </div>
            <div class="swipper">
                <van-swipe class="my-swipe" :autoplay="3000" indicator-color="white">
                    <van-swipe-item v-for="item in shopList" :key="item.id">
                        <img class="swiper_item_image" :src="item.src" />
                    </van-swipe-item>
                </van-swipe>
                <div class="team_price">
                    <div class="price">
                        <p>
                            ¥<b>0.</b><span>88&nbsp;{{ teamType == 2 ? '起' : ''}}</span>
                            <span class="bread" v-if="teamType == 0">5人拼团价</span>
                            <span class="bread" v-if="teamType == 1">新人优惠</span>
                            <span class="bread" v-if="teamType == 2">人多更优惠</span>
                        </p>
                        <p class="old_price">¥1</p>
                    </div>
                    <div class="time">
                        <p>距{{ invalidTime ? '开始' : '结束' }}仅剩</p>
                        <van-count-down :time="countdown" format="DD 天 HH 时 mm 分 ss 秒" />
                        <!-- <p>7天<span>{{ countdown }}</span></p> -->
                    </div>
                </div>            
            </div>
            <div class="goods_title">
                <div class="goods_main">
                    <h6 class="title_warp">213213</h6>
                    <div class="icon_warp" @click="deliverFriend">
                        <img :src="giftIconURL" alt="" />
                        <h6 class="name">送好友</h6>
                    </div> 
                </div>
                <div class="author_reading" v-if="record > 0">2024.02.29&nbsp;|&nbsp;7次学习</div>
            </div>
            <div class="team_rules">
                <div class="rules_item" style="padding: 0 10px 10px 10px;" @click="teamRuleVisible = true">
                    <div class="rules_item_cell">
                        <label>拼团玩法{{ teamType == 2 ? '-阶梯拼团' : '' }}</label>
                        <van-icon name="arrow" />
                    </div>
                    <div class="message" v-if="teamType == 0">开团后邀请4人参团则拼团成功，人数不够则自动退款。</div>           
                    <div class="message" v-if="teamType == 2">2人团¥0.88/人，3人团¥0.77/人，4人团¥0.66/人，人满拼团成功，人数不够则自动退款。</div>           
                    <div class="rule_new" v-if="teamType == 1">
                        <div class="new_title">邀新<br />专享</div>
                        <div class="new_progress">
                            <div class="step">
                                <van-icon name="records" />
                                <span class="text">1.下单开团</span>
                            </div>
                            <div class="line" style="left: 22%;"></div>
                            <div class="step">
                                <van-icon name="friends" />
                                <span class="text">2.邀请新人参团</span>
                            </div>
                            <div class="line" style="left: 60%;"></div>
                            <div class="step">
                                <van-icon name="completed" />
                                <span class="text">3.人满发货不满退款</span>
                            </div>
                        </div>
                    </div>      
                </div>
                <div class="rules_item">
                    <div class="rules_item_cell" @click="viewEvaluate">
                        <h4 class="main">评价</h4>
                        <p class="evaluate">暂无评价<van-icon name="arrow" /></p>                    
                    </div>                
                </div>
                <div class="rules_item">
                    <div class="rules_item_cell">
                        <h4>{{ shopname }}</h4>
                        <van-button round plain color="#105cfb" size="small" @click="GoHome">进店看看</van-button>                    
                    </div>                
                </div>
            </div>
            <div class="custom_tabs">
                <van-tabs v-model:active="activeName">
                    <van-tab title="详情" name="d">
                        <div class="noData">
                            <van-icon name="newspaper-o" />
                            <h6>暂无详情</h6>
                        </div>
                    </van-tab>
                    <van-tab title="目录" name="m">
                        <div class="noData">
                            <van-icon name="newspaper-o" />
                            <h6>暂无目录</h6>
                        </div>
                    </van-tab>
                </van-tabs>
            </div>
            <div class="company_intro">
                <ul class="link_group">
                    <li>店铺主页</li>&nbsp;|&nbsp;
                    <li>个人中心</li>&nbsp;|&nbsp;
                    <li>投诉建议</li> 
                </ul>            
                <p class="support_name">知了提供技术支持</p>
            </div>
            <div class="new_inviting">
                <div class="footer_btn_group">
                    <div class="separate_buy" @click="buyProduct(0)">
                        <div class="name">单独购买</div>
                        <div class="price">￥1.00</div>
                    </div>
                    <div class="immed_open_group" :class="{'immed_gray': invalidTime }" @click="buyProduct(1)">
                        <div class="name">立即开团</div>
                        <div class="price">￥0.88</div>
                    </div>
                </div>            
            </div>
        </div>        
        <van-dialog v-model:show="teamRuleVisible" title="拼团玩法" theme="round-button" confirm-button-text="知道了" round-button>
            <div class="rules_intro">
                <h4>什么是拼团？</h4>
                <p>拼团是指由多人一起拼单购买的团购活动，通过拼团买家可享受比一般网购更低的折扣。</p>
                <h4 v-if="teamType == 1">怎么算新人?</h4>
                <p v-if="teamType == 1">新人,即店铺内未提交过订单的用户(订单提交后未付款的用户,不视为新人).</p>
                <h4>怎么算拼团成功?</h4>
                <p>在拼团有效期内找到足够人数的好友参加拼团，即可算拼团成功。</p>
                <h4>拼团失败，怎样退款?</h4>
                <p>若拼团有效期内没有凑齐人数，即算作拼团失败。系统会自动将所支付的金额原路退回，具体到账时间以实际操作为准。</p>
            </div>
        </van-dialog>
    </div>
</template>

<script>
import { debounce } from 'lodash'; 
import { nanoid } from 'nanoid';
export default{
    data(){
        return {
            teamType: 2,    // 0-普通拼团,1-邀新拼团,2-阶梯拼团
            shopname: '邓波测试店铺',
            activeName: 'd',
            searchVisible: false,
            keyword: '',
            giftIconURL: require('@/assets/img/gift_icon.png'),
            shopList: [
                { id: nanoid(),src: require('@/assets/img/share_picture.png') },
                { id: nanoid(),src: require('@/assets/img/share_picture.png') },
            ],
            countdown: 108000000,
            teamRuleVisible: false,
            record: 0,
            invalidTime: true,    // 无效时间内
        }
    },
    created(){

    },
    mounted(){

    },
    methods: {
        searchProduct(){    // 搜索
            console.log('search');
            this.searchVisible = true;
        },        
        cancelSearch(){ // 取消
            console.log('cancel search');
            this.searchVisible = false;
        },
        searchKeyword: debounce(function(){    // 搜索输入框
            console.log('input',this.keyword);
        },500),
        GoPersonCenter(){   // 个人中心
            let shopname = this.$route.query.domainname;
            console.log('个人中心',shopname);
            this.$router.push(`/xuejing/my/${shopname}`);
        },
        deliverFriend(){    // 送好友
            console.log('送好友');
        },
        viewEvaluate(){ // 评价
            console.log('评价');
        },
        GoHome(){   // 进店看看
            let domainname = this.$route.query.domainname;
            console.log('进店看看',domainname);

            this.$router.push(`/shop/${domainname}`);
        },
        buyProduct(n){  // 单独购买-0，立即开团
            if (n > 0) {
                if (this.invalidTime) {
                    this.$toast.fail('活动时间未开始，不能开团');
                } else {
                    console.log('立即开团');
                }
            } else {
                console.log('单独购买');
            }
        }
    }
}
</script>

<style lang="scss" scoped>
.share_wrapper{
    background-color: #f5f5f5;
    .search_wrapper{
        height: 100%;
        background-color: #fff;
        position: relative;
        overflow: hidden;
        .search_filter{
            box-sizing: border-box;
            padding: 10px 60px 10px 10px;
            display: flex;
            justify-content: space-between;
            align-items: center;
            position: relative;
            overflow: hidden;
            .el-input{

            }
            .el-button{
                position: absolute;
                right: 20px;
                top: 10px;
            }
        }
        .company_intro{
            width: 100%;
            position: absolute;
            left: 0;
            bottom: 0;        
            overflow: hidden;
            .link_group{
                height: 40px;
                display: flex;
                justify-content: center;
                align-items: center;
                color: #666;
                li{
                    font-size: 14px;                
                }
            }
            .support_name{
                font-size: 13px;
                text-align: center;
                color: #999;
                margin: 0 0 20px 0;
            }
        }
    }
    .share_column{
        .header{
            width: 100%;
            height: 60px;
            padding: 0 10px;
            display: flex;
            align-items: center;
            justify-content: space-between;
            background-color: #fff;
            box-shadow: 0 3px 6px 0 rgba(0,0,0,0.05);
            box-sizing: border-box;
            overflow: hidden;
            .title{
                font-size: 18px;
                font-weight: normal;
            }
            .person_center{
                display: flex;            
                .van-icon{
                    font-size: 24px;
                }
                .name{
                    font-size: 16px;
                    color: #4a4c5b;
                    margin: 0 0 0 5px;
                }
            }
        }
        .swipper{
            width: 100%;
            margin: 10px 0 0 0;
            .swiper_item_image{
                display: block;
                width: 100%;
            }
            .team_price{
                display: flex;
                justify-content: space-between;
                align-items: center;
                padding: 10px;
                background-color: #fe6500;
                background-image: linear-gradient(90deg, #ff4102, #fe6500) !important;
                color: #fff;
                .price{
                    b{
                        font-size: 26px;
                        margin: 0 4px;
                    }
                    .old_price{
                        text-decoration: line-through;
                        opacity: .6;
                    }
                    .bread{
                        display: inline-block;
                        height: 18px;
                        border-radius: 9px;
                        background-color: #fff;
                        padding: 0 10px;
                        color: #ff4c51;
                        font-size: 12px;
                        line-height: 18px;
                        margin: 0 0 0 10px;
                        transform: translateY(-5px);
                    }
                }
                .time{
                    font-size: 14px;
                    text-align: right;
                    .van-count-down{                        
                        color: #fff;
                    }
                }
            }
        }
        .goods_title{
            padding: 10px;
            background-color: #fff;
            overflow: hidden;
            .goods_main{
                display: flex;
                align-items: center;
                justify-content: space-between;
                .title_warp{
                    font-size: 16px;
                }
                .icon_warp{
                    -webkit-user-select: none;
                    user-select: none;
                    img{
                        display: block;
                        width: 24px;
                        margin: 0 auto 5px;
                    }
                    .name{
                        font-size: 10px;
                        color: #999;
                    }
                }
            }
            .author_reading{
                margin: 9px 0 0 0;
                font-size: 14px;
                color: #999;
            }
        }
        .team_rules{
            margin: 10px 0 0 0;
            .rules_item{
                margin: 0 0 10px 0;
                padding: 0 10px;
                background-color: #fff;
                overflow: hidden;
                .rules_item_cell{
                    display: flex;
                    padding: 10px 0;
                    align-items: center;
                    justify-content: space-between;
                    font-size: 16px;
                    label{
                        color: #999;
                        span{
                            display: inline-block;
                            margin: 0 0 0 10px;
                            color: #333;
                        }
                    }
                    .evaluate{
                        font-size: 15px;
                        color: #333;
                    }
                    .van-icon-arrow{
                        color: #bfbfbf;
                    }
                    .main{
                        font-weight: bold;
                    }
                }
                .message{
                    padding: 0 0 10px 0;
                }
                .rule_new{
                    position: relative;
                    padding: 10px 0 10px 80px;
                    .new_title{
                        font-size: 15px;
                        font-weight: bold;
                        color: #ff2c2c;
                        position: absolute;
                        left: 10px;
                        top: 10px;
                    }
                    .new_progress{
                        display: flex;
                        justify-content: space-between;
                        align-items: center;
                        position: relative;
                        .step{
                            display: flex;
                            flex-direction: column;
                            align-items: center;
                            font-size: 10px;
                            .van-icon{                           
                                font-size: 24px;                            
                                color: #ff2c2c;
                            }
                            .text{
                                display: block;
                                margin: 5px 0 0 0;
                                color: #333;
                            }
                        }
                        .line{
                            width: 25px;
                            height: 1px;
                            background-color: #ff2c2c;
                            position: absolute;
                            top: 15px;
                        }
                    }
                }
            }
        }

        .custom_tabs{
            .van-tabs{
                .van-tabs__content{
                    .noData{
                        text-align: center;
                        color: #999;
                        background-color: #fafafa;
                        border-radius: 0.16rem;
                        height: 200px;
                        padding: 50px 0 0 0;
                        box-sizing: border-box;
                        .van-icon{
                            font-size: 24px;
                        }
                        h6{
                            font-size: 13px;
                            font-family: PingFangSC-Regular, PingFang SC;
                            font-weight: 400;
                            color: #999;
                        }
                    }
                }
            }
        }
        .company_intro{
            overflow: hidden;
            .link_group{
                height: 40px;
                display: flex;
                justify-content: center;
                align-items: center;
                color: #666;
                li{
                    font-size: 14px;                
                }
            }
            .support_name{
                font-size: 13px;
                text-align: center;
                color: #999;
                margin: 0 0 20px 0;
            }
        }
        .share_btn_group{
            width: 100%;
            position: fixed;
            bottom: 0;
            left: 0;
            .van-button{
                display: block;
                width: 90%;
                margin: 5px auto;
            }
        }
        .new_inviting{
            width: 100%;
            position: fixed;
            bottom: 0;
            left: 0;
            .footer_btn_group{
                display: flex;
                justify-content: space-between;
                align-items: center;
                width: 100%;
                box-sizing: border-box;
                box-shadow: 0 -2px 3px #eee;
                background-color: #fff;
                padding: 10px 15px;  
                -webkit-user-select: none;
                user-select: none;
                .separate_buy{
                    width: 50%;
                    padding: 5px 0;
                    border-radius: 25px 0 0 25px;
                    background-color: #fff3eb;
                    text-align: center;
                    color: #ff781f;
                    .name{
                        font-size: 13px;
                    }
                    .price{
                        font-size: 15px;
                    }
                }
                .immed_open_group{
                    width: 50%;
                    padding: 5px 0;
                    border-radius: 0 25px 25px 0;
                    background: linear-gradient(90deg, #ff4f3b 0%, #ff373e 50%, #fe1f41 100%);
                    text-align: center;
                    color: #fff;
                    .name{
                        font-size: 13px;
                    }
                    .price{
                        font-size: 15px;
                    }
                }
                .immed_open_group.immed_gray{
                    background: #ebebeb;
                }
            }
        }
    }

    .van-popup{
        padding: 0 0 30px 0;
        .delivery_item{
            color: #333;
        }
        .delivery_item.curDelivery{
            color: #105cfb;
        }
    }  
    .van-dialog{
        ::v-deep .van-dialog__header{
            font-size: 18px;
            font-weight: bold;
            margin: 0 0 20px 0;
            color: #333;
        }
        .van-dialog__content{
            .rules_intro{
                padding: 0 30px;
                h4{
                    font-weight: bold;
                    font-size: 16px;
                    line-height: 36px;
                }
                p{
                    font-size: 13px;
                    line-height: 18px;
                    color: #666;
                    margin: 0 0 10px 0;
                }
            }
        }
    }  
}
</style>